﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Castle.Facilities.TypedFactory;
using Castle.MicroKernel.Registration;
using Mammoth.Repositories;
using Mammoth.Services;

namespace Mammoth.Factories
{
    public class ServiceInstaller : IWindsorInstaller
    {
        public void Install(Castle.Windsor.IWindsorContainer container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
        {
            //factories
            container.AddFacility<TypedFactoryFacility>();
            container.Register(Component.For<IRepositoryFactory>().AsFactory());
            var vf = new ViewFactory(container);
            container.Register(Component.For<IViewFactory>().Instance(vf));
            var vmf = new ViewModelFactory(container);
            container.Register(Component.For<IViewModelFactory>().Instance(vmf));

            //services
            container.Register(Component.For<IDatabaseConfiguration>()
                .Forward<IGTalkConfiguration>()
                .ImplementedBy<MammothConfig>()
                .UsingFactoryMethod(x => MammothConfig.Load()));
        }
    }
}
